/**
 * 2609. 最长平衡子字符串
 */
public class No2609 {
    public int findTheLongestBalancedSubstring(String s) {
        int ans = 0;
        int curZero = 0, curOne = 0, i = 0;
        while (i < s.length()) {
            while (i < s.length() && s.charAt(i) == '0') {
                curZero++;
                i++;
            }
            while (i < s.length() && s.charAt(i) == '1') {
                curOne++;
                i++;
            }
            ans = Math.max(ans, 2 * Math.min(curZero, curOne));
            curZero = 0;
            curOne = 0;
        }
        return ans;
    }
}
